export function defaultToString(item: any): string {
  if (item === null) {
    return "NULL"
  }
  if (item === undefined) {
    return "UNDEFINED"
  }
  if (typeof item === "string" || item instanceof String) {
    return `${item}`
  }
  return item.toString();

}

export class loseloseHashCode {
  toStringFn: Function;
  modulusNum: number;

  constructor(toStringFn: Function = defaultToString, modulusNum: number = 36) {
    this.toStringFn = toStringFn
    this.modulusNum = modulusNum
  }


  getCode(key: any):number {
    if (typeof key === "number") {
      return key;
    }
    const str = this.toStringFn(key);
    let hash = 0;
    for (let i = 0, len = str.length; i < len; i++) {
      hash += str.charCodeAt(i)
    }
    hash = hash % this.modulusNum
    return hash;
  }
}

